package com.tich.common.controller;

import com.tich.common.domain.vo.CaptchaVO;
import com.tich.common.service.CommonService;
import com.tich.constant.ResponseMessageConstant;
import com.tich.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/common")
public class CommonController {

    @Autowired
    private CommonService commonService;

    /**
     * 生成图形验证码
     * @return
     * */
    @GetMapping("/captcha")
    public Result<CaptchaVO> captcha(){
        log.info("获取图形验证码");
        return Result.success(ResponseMessageConstant.CREATE_CAPTCHA_SUCCESS, commonService.captcha());
    }

    /**
     * 上传头像
     * @param files
     * @param type
     * @return
     * */
    @PostMapping("/upload/image")
    public Result<List<String>> upload(List<MultipartFile> files, Integer type){
        log.info("上传文件, 文件：{}, 种类, {}", files, type);
        return Result.success(ResponseMessageConstant.UPLOAD_SUCCESS, commonService.upload(files, type));
    }



}
